package model.admin;

import myutil.Connect;


import vo.DepartmentDetailsVo;

public class ModifyDepartmentsMo {

	public Boolean updateDepartmentDetails(DepartmentDetailsVo department_details){
	String query="update department_details" +
			     "   set department_name	=	'"+department_details.getDepartment_name()+"' ," +
			     "  	 description		=	'"+department_details.getDescription()+"' " +
			     " where department_id		=	"+department_details.getDepartment_id()+";";
		Connect c = new Connect();
		System.out.println("query is \t"+query+" \n");
		try{c.dml(query);return true;}
		catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());e.printStackTrace();return false;
		}
		
	}
	public Boolean deleteDepartmentDetails(int batch_id, int department_id){
		String query="update degree_department  " +
				     "   set status	=	0 " +
					 " where department_id 	=	"+department_id+" " +
					 "   and batch_id 		=	"+batch_id+";";
		if (batch_id==0)
			query="update department_details  " +
				     "   set status	=	0 " +
					 " where department_id 	=	"+department_id+";";
		Connect c = new Connect();
		System.out.println(query);
		try{c.dml(query); return true;}
		catch (Exception e) {
			// TODO: handle exception
		System.out.println(e.getMessage());
		e.printStackTrace();
		return false;
		}
	}

	public boolean addBatchDepartmentDetails(String department_name,
			String description, int batch_id, int start_year) {
		String query = "";
		query="INSERT INTO degree_department (" +
				"department_id," +
				"degree_id," +
				"batch_id, " +
				"start_year, " +
				"description, " +
				"status)" +
				" VALUES " +
				"((select department_id from department_details where department_name='"+department_name+"')," +
				" (select degree_id from degree_management where batch_id=" + batch_id+"),"+
				batch_id+",'"+
				start_year+"'," +
				"'"+description+"'," +
				"'1');";
		Connect c = new Connect();
		System.out.println(query);
		try{c.dml(query); return true;}
		catch (Exception e) {
			// TODO: handle exception
		System.out.println(e.getMessage());
		e.printStackTrace();
		return false;
		}
	}
		public Boolean addNewDepartment(DepartmentDetailsVo department) {
			String query = "INSERT INTO department_details (" + "department_name, "
					+ "start_year, " + "description, " + "status) VALUES ('"
					+ department.getDepartment_name() + "', '"
					+ department.getStart_year() + "', '"
					+ department.getDescription() + "', '" + "1');";
			Connect c = new Connect();
			try {
				c.dml(query);
				return true;
			} catch (Exception e) {
				// TODO: handle exception
				return false;
			}
		}
	}
